<?php

namespace App\Http\Controllers;

use App\Exceptions\BusinessException;
use App\Services\RefundService;
use App\Services\WechatService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RefundController extends Controller
{
    /**
     * 退款
     * @param Request $request
     * @return JsonResponse
     * @throws BusinessException
     */
    public function refund(Request $request)
    {
        $uid = $request->uid;
        $orderId = $request->post('order_id');
        $sellType = $request->post('sell_type');
        $sellId = $request->post('sell_id');
        $refundReason = $request->post('refund_reason');
        RefundService::getInstance()->refund($uid, $orderId, $sellType, $sellId, $refundReason);

        return $this->success();
    }

    /**
     * 退款审核
     * @param Request $request
     * @return JsonResponse
     * @throws BusinessException
     */
    public function refundCheck(Request $request)
    {
        $refundId = $request->post('refund_id');
        $checkStatus = $request->post('check_status');
        $rejectReason = $request->post('reject_reason');

        RefundService::getInstance()->refundCheck($refundId, $checkStatus, $rejectReason);

        return $this->success();
    }

    /**
     * 退款回调
     * @param Request $request
     * @return void
     */
    public function notify(Request $request)
    {
        WechatService::getInstance()->refundNotify();
    }
}
